package io.bdmc.modules.bss.controller;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.bdmc.common.annotation.SysLogger;
import io.bdmc.common.utils.R;
import io.bdmc.modules.bss.entity.DeviceLinkGroup;
import io.bdmc.modules.bss.service.IDeviceLinkGroupService;
import io.bdmc.modules.sys.controller.AbstractController;

/**
 * <p>
 * 链路视图组 前端控制器
 * </p>
 *
 * @author 黄露
 * @since 2021-06-25
 */

// "链路视图组", description = "链路视图组")
@RestController
@RequestMapping("/bss/link/group")
public class DeviceLinkGroupController extends AbstractController {

	@Autowired
	IDeviceLinkGroupService _devicelinkgroupSvs;

	@GetMapping("/tree")
	// "链路视图树", notes = "链路视图树")
	public R tree() {
		List<HashMap<String, Object>> map = _devicelinkgroupSvs.routeTree(getDeptId().intValue());
		return R.ok().putData(map);
	}

	@GetMapping("/info")
	// "查询路由组", notes = "查询路由组")
	public R list(int linkGroupId) {
		return R.ok().putData(_devicelinkgroupSvs.getById(linkGroupId));
	}

	@SysLogger("新增链路视图组")
	@PostMapping("/add")
	// "新增链路视图组", notes = "新增链路视图组")
	public R add(@RequestBody DeviceLinkGroup devicelinkgroup) {
		devicelinkgroup.setCreateBy(getUser().getUsername());
		devicelinkgroup.setCreateTime(LocalDateTime.now());
		devicelinkgroup.setDeptId(getDeptId().intValue());
		Boolean b = devicelinkgroup.insert();
		return R.trueOrFalse(b);
	}

	@SysLogger("修改链路视图组")
	@PostMapping("/update")
	// "修改链路视图组", notes = "修改链路视图组")
	public R update(@RequestBody DeviceLinkGroup devicelinkgroup) {
		Boolean b = devicelinkgroup.updateById();
		return R.trueOrFalse(b);
	}

	@SysLogger("删除链路视图组")
	@PostMapping("/delete")
	// "删除链路视图组", notes = "删除链路视图组")
	public R delete(@RequestBody Integer linkGroupId) {
		if (linkGroupId > 0)
			_devicelinkgroupSvs.removeById(linkGroupId);
		return R.ok();
	}
}
